const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  // return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  return [month, day].map(formatNumber).join('/')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}


const checkPhoneNumber = input =>{
  let value = parseInt(input)
    if(value<9999999999 || 100000000000<value){
      return false  
    }else{
      return true
    }  
}

const checkIDCardNumber = input =>{
  let value = parseInt(input)
    if(value<420000000000000000 || 450000000000000000<value){
      return false  
    }else{
      return true
    }  
}

const add0 = m => {
  return m < 10 ? '0' + m : m
}

const format = function(timeStamp) {
  //timeStamp是整数，否则要parseInt转换

  if(typeof(timeStamp) != typeof(666))
  {
    timeStamp = parseInt(timeStamp)
  }
  var time = new Date(timeStamp);
  var y = time.getFullYear();
  var m = time.getMonth() + 1;
  var d = time.getDate();
  return y + '-' + this.add0(m) + '-' + this.add0(d)
}

module.exports = {
  formatTime: formatTime,
  checkPhoneNumber: checkPhoneNumber,
  checkIDCardNumber: checkIDCardNumber,
  format: format
}



